#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @author: zzll0909
# @file: 1.py
# @time: 2022/11/09
# @software: VS Code

class Solution:
    def twoSum(self, nums: list[int], target: int) -> list[int]:
        # 用字典存储值和索引关系，查找比较快
        # num_dict结构：[值，索引]
        num_dict = dict()
        result = list()
        for i in range(len(nums)):
            if target - nums[i] in num_dict:
                result = [num_dict[target - nums[i]], i]
            num_dict[nums[i]] = i
        return result


if __name__ == "__main__":
    nums = [3, 3]
    target = 6
    solu = Solution()
    result = solu.twoSum(nums, target)
